home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
windc.exe
/
SAMPLE1.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-07
|
13KB
|
410 lines
/* sample of basic functions */
#include <stdio.h>
#include <dos.h>
#include <memory.h>
#include "wwindefs.h" /* window headers */
#include "wwinstpr.h"
/* subroutine prototypes */
void Example1();
void Example2();
void Example3();
void Example4();
void Example5();
extern WWVIDMEM WWscreenp; /* pointer to screen memory */
extern unsigned int WWScreenLength; /* access to WW defaults */
extern unsigned int WWScreenWidth;
/* define caption window - globally */
struct WWinstruc Caption =
{"Caption",22,2,10,60, WHITE,BLACK,SLN_BDR,WHITE,BLACK,INV_CSR};
main()
{
int i, rc;
WWscreenp = WWCOLMEM; /* unecessary - color screen memory is default*/
for (i=0;i<27;i++) /* clear screen */
printf(" "
" ");
if ((rc = WWinDef(&Caption)) !=0) /* set up caption screen */
{printf("out of memory"); exit(1);}
WWinLoad(&Caption,2,2,NC,NC,"Press ESC to exit this example",0);
WWinPut(&Caption);
WWinCurSet(&Caption,1,1); /* set cursor out of the way */
Example1();
Example2();
Example3();
Example4();
Example5();
Caption.Cursor = NRM_CSR; /* make cursor normal */
WWinCurSet(&Caption,Caption.UseLength,1); /* restore cursor */
}/* end main */
void Example1()
{
/* this example shows how the WWinPut and WWinErase functions
* can be used to move a window around on the screen.
* note: the TopRow and LeftCol items in the WWinstruc can be changed
* at any time after the window has been defined. BUT- be sure the
* window is inactive (i.e., not on the screen) while changing these
* values.
* Also, you must make sure the entire window will fit on the screen
* to avoid a fatal error.
*/
struct WWinstruc WinOne =
{"WinOne",5,3,8,10, BLUE,CYAN,SLN_BDR,RED,BLACK,INV_CSR};
int rc;
char inkey;
WWinLoad(&Caption,1,2,NC,NC,"EX-1 - Press arrow keys to move window",0);
WWinPut(&Caption);
if ((rc = WWinDef(&WinOne)) != 0)
{printf("out of memory"); exit(1);}
inkey = 0;
WWinPut(&WinOne);
while (inkey != 27)
{
WWinPut(&WinOne);
do /* accept */
inkey = getch(); /* only */
while ( (inkey != 0) && (inkey != 27) ); /* ctl keys and ESC */
if (inkey != 27)
{
inkey = getch(); /* get scan code */
switch(inkey)
{
case 72: /* up arrow */
WWinErase(&WinOne);
if (WinOne.TopRow > 1+(WinOne.Border > 0)) WinOne.TopRow--;
WWinPut(&WinOne);
break;
case 80: /* down arrow */
WWinErase(&WinOne);
if (WinOne.TopRow + WinOne.UseLength-(WinOne.Border == 0)
< WWScreenLength) WinOne.TopRow++;
WWinPut(&WinOne);
break;
case 75: /* left arrow */
WWinErase(&WinOne);
if (WinOne.LeftCol > 1+(WinOne.Border > 0)) WinOne.LeftCol--;
WWinPut(&WinOne);
break;
case 77: /* right arrow */
WWinErase(&WinOne);
if (WinOne.LeftCol + WinOne.UseWidth-(WinOne.Border == 0)
< WWScreenWidth) WinOne.LeftCol++;
WWinPut(&WinOne);
break;
default:
break;
}
}/* if != 27 */
}/* while != 27 */
WWinDrop(&WinOne); /* erase if necessary and free all memory */
}/* end Example1 */
void Example2()
{
/* this example demonstrates the WWinLoad and WWinClear functions
* including writing to the border
*/
struct WWinstruc WinOne =
{"WinOne",5,10,4,70, BLUE,CYAN,DLN_BDR,RED,BLACK,INV_CSR};
int rc;
char inkey;
WWinLoad(&Caption,1,2,NC,NC,"EX-2 - Press ENTER to continue . . . ",0);
WWinLoad(&Caption,1,15,NCB,NC,NULL,5); /* blink the word ENTER */
WWinPut(&Caption);
if ((rc = WWinDef(&WinOne)) != 0)
{printf("out of memory"); exit(1);}
inkey = 0;
WWinLoad(&WinOne,WinOne.UseLength+1,30,NC,NC, /* load border with text */
"Example 2",0);
WWinLoad(&WinOne,1,2,NC,NC,
"This phrase is loaded with default background and text colors",0);
WWinPut(&WinOne);
inkey = getch();
if (inkey != 27)
{
WWinLoad(&WinOne,2,2,BLACK,RED,
"This phrase is loaded with black background and red text",0);
WWinPut(&WinOne);
inkey = getch();
if (inkey != 27)
{
WWinLoad(&WinOne,3,2,NCB,NCB,
"This phrase is loaded with blink default background"
" and bright default text colors",0);
WWinPut(&WinOne);
inkey = getch();
if (inkey != 27)
{
WWinLoad(&WinOne,5,2,BLACK|BLINK,RED|BRIGHT,
"This phrase is loaded with blink black background"
" and bright red text",0);
WWinPut(&WinOne);
inkey = getch();
if (inkey != 27)
{
WWinLoad(&WinOne,7,2,NC,NC,
"Half the previous phrase is changed"
" to NOT BLINK and NOT BRIGHT",0);
WWinLoad(&WinOne,5,2,NCN,NCN,NULL,35);
WWinPut(&WinOne);
inkey = getch();
if (inkey != 27)
{
/* clears memory to blanks and attributes from structure */
WWinClear(&WinOne);
WWinPut(&WinOne); /* puts cleared memory to screen */
inkey = getch();
}
}
}
}
}
WWinDrop(&WinOne); /* erase if necessary and free all memory */
WWinLoad(&Caption,1,15,NCN,NC,NULL,5); /* un-blink ENTER */
}/* end example 2 */
void Example3()
{
/* This example demonstrates changing the size and shape of a window
* and changing border values
* note: the size of a window can be changed after it is defined, BUT-
* (1) the area of the window (length * width plus borders) must be set
* to the maximum when WWinDef is executed.
* (2) the window must be inactive when size changes are being made.
* (3) if the window has borders, the WWinBorder function must be
* executed after a size change to reset the borders.
* (4) if the UseWidth is changed, the MemWidth value may be
* identically changed to force wrap. If MemWidth is not
* changed truncation occurs(more about this in the next
* example).
* Also, you must make sure the entire window will fit on the screen
* to avoid a fatal error.
*/
struct WWinstruc WinOne =
{"WinOne",5,15,10,30, BLUE,CYAN,DLN_BDR,RED,BLACK,INV_CSR};
int i, j, rc, maxsize;
char inkey, alpharow[3], alphacol[3];
extern unsigned char WWBorder_Cons[4][6]; /* access WW border styles */
unsigned char newborder[6] = {2,1,2,1,2,2}; /* smiley-face border */
/* replace blank border with smiley faces */
memcpy(WWBorder_Cons[3],newborder,6);
WWinLoad(&Caption,1,2,NC,NC,
"EX-3 - Press 'l' or 's' to re-size window & change borders",0);
WWinPut(&Caption);
if ((rc = WWinDef(&WinOne)) != 0)
{printf("out of memory"); exit(1);}
for(i=1;i<16;i++) /* load pattern into window-memory */
for(j=1;j<30;j+=15)
{
WWinLoad(&WinOne,i,j+1,NC,NC,"row ",0);
alpharow[0] = '0';
itoa(i,alpharow+(i<10),10);
WWinLoad(&WinOne,i,j+5,NC,NC,alpharow,0);
WWinLoad(&WinOne,i,j+7,NC,NC," col ",0);
itoa(j+14,alphacol,10);
WWinLoad(&WinOne,i,j+12,NC,NC,alphacol,0);
}
inkey = 0;
/* save max window area for test limit */
maxsize = WinOne.UseLength * WinOne.UseWidth;
while (inkey != 27)
{
WWinPut(&WinOne);
do
inkey = getch();
while ( (toupper(inkey) != 'S')
&& (toupper(inkey) != 'L')
&& (inkey != 27) ); /* only s & l keys and ESC */
if (inkey != 27)
{
WWinErase(&WinOne);
switch(toupper(inkey))
{
case 'S': /* smaller */
if (WinOne.UseLength > 1) WinOne.UseLength--;
if (WinOne.UseWidth > 2)
{
WinOne.UseWidth-=2;
WinOne.MemWidth-=2; /* force wrap */
}
WinOne.Border = (++WinOne.Border)%4; /* cycle borders */
WWinBorder(&WinOne); /* for variety */
break;
case 'L': /* larger */
if (WinOne.UseLength * WinOne.UseWid